package com.zfc.life.controller.frontend;

import com.zfc.life.domain.Resource;
import com.zfc.life.domain.vo.ResourceVo;
import com.zfc.life.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * @author zfc
 * @Date 2024/5/24 8:54
 * @Description PageController
 */
@Controller
public class PageController {

    @GetMapping("/login")
    public String login() {
        return "backend/login";
    }

    @Autowired
    private ResourceService resourceService;

    @GetMapping({"/", "/index"})
    public String index(ModelMap mmap) {

        List<ResourceVo> resourceList = resourceService.frontendResourceList();
        mmap.put("resourceList", resourceList);
        return "frontend/index";
    }

    @GetMapping("/detail")
    public String detail(Long parent, ModelMap mmap) {

        //1、通过parent查询资源
        Resource resource = resourceService.querySubjectById(parent);
        mmap.put("resource", resource);

        //2、根据parent查询子资源
        mmap.put("detail", resourceService.selectResourceByParent(parent));
        return "frontend/detail";
    }
}
